package com.drg.center.controller;

import com.drg.center.entity.param.*;
import com.drg.center.entity.result.*;
import com.drg.center.service.DataStatAnalysisService;
import com.drg.center.service.StatisticsDoctorFromEsService;
import com.guaike.core.entity.result.PageEntity;
import com.guaike.core.entity.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

@Slf4j
@RestController
@RequestMapping("/dataStat")
@Api(tags = "数据统计分析接口组")
@AllArgsConstructor
public class DataStatAnalysisController {

    private final DataStatAnalysisService dataStatAnalysisService;
    private final StatisticsDoctorFromEsService statisticsDoctorFromEsService;

    @GetMapping("/totalHospitalCostAnalysis")
    @ApiOperation(value = "全院DRG费用分析")
    public Result<TotalDrgCostAnalysisVO> totalHospitalCostAnalysis(@Valid DrgCostAnalysisDTO param) {
        return dataStatAnalysisService.totalHospitalCostAnalysis(param);
    }

    @GetMapping("/caseProfitLossPage")
    @ApiOperation(value = "病例盈亏预测列表")
    public Result<PageEntity<CaseProfitLossPageVO>> caseProfitLossPage(@Valid CaseProfitLossDTO param) {
        return dataStatAnalysisService.caseProfitLossPage(param);
    }

    @GetMapping("/exportCaseProfitLosExcel")
    @ApiOperation(value = "导出病例盈亏预测excel")
    public void exportCaseProfitLosExcel(HttpServletResponse response, CaseProfitLossDTO param) throws Exception {
        dataStatAnalysisService.exportCaseProfitLosExcel(response, param);
    }

    @GetMapping("/caseProfitLossAnalysisPage")
    @ApiOperation(value = "病例盈亏分析列表")
    public Result<PageEntity<CaseProfitLossAnalysisPageVO>> caseProfitLossAnalysisPage(@Valid CaseProfitLossDTO param) {
        return dataStatAnalysisService.caseProfitLossAnalysisPage(param);
    }

    @GetMapping("/caseProfitLossAnalysis")
    @ApiOperation(value = "病例盈亏分析统计")
    public Result<CaseProfitLossAnalysisVO> caseProfitLossAnalysis(@Valid CaseProfitLossDTO param) {
        return dataStatAnalysisService.caseProfitLossAnalysis(param);
    }

    @GetMapping("/exportCaseProfitLossAnalysisExcel")
    @ApiOperation(value = "导出病例盈亏分析excel")
    public void exportCaseProfitLossAnalysisExcel(HttpServletResponse response, CaseProfitLossDTO param) throws Exception {
        dataStatAnalysisService.exportCaseProfitLossAnalysisExcel(response, param);
    }

    @GetMapping("/departDataOverview")
    @ApiOperation(value = "科室数据总览")
    public Result<DepartDataVO> departDataOverview(@Valid DepartDataDTO param) {
        return dataStatAnalysisService.departDataOverview(param);
    }

    @GetMapping("/departProfitLossAnalysis")
    @ApiOperation(value = "科室盈亏分析列表")
    public Result<List<DepartProfitLossPageVO>> departProfitLossAnalysis(@Valid DepartProfitLossDTO param) {
        return dataStatAnalysisService.departProfitLossAnalysis(param);
    }

    @GetMapping("/exportDepartProfitLossAnalysisExcel")
    @ApiOperation(value = "导出科室盈亏分析excel")
    public void exportDepartProfitLossAnalysisExcel(HttpServletResponse response, DepartProfitLossDTO param) throws Exception {
        dataStatAnalysisService.exportDepartProfitLossAnalysisExcel(response, param);
    }

    @GetMapping("/departCostAnalysis")
    @ApiOperation(value = "科室费用分析汇总列表")
    public Result<List<DepartCostPageVO>> departCostAnalysis(@Valid DepartCostDTO param) {
        return dataStatAnalysisService.departCostAnalysis(param);
    }

    @GetMapping("/exportDepartCostAnalysisExcel")
    @ApiOperation(value = "导出科室费用分析汇总excel")
    public void exportDepartCostAnalysisExcel(HttpServletResponse response, DepartCostDTO param) throws Exception {
        dataStatAnalysisService.exportDepartCostAnalysisExcel(response, param);
    }

    @GetMapping("/drgProfitLossAnalysis")
    @ApiOperation(value = "病组盈亏统计列表")
    public Result<List<DrgProfitLossPageVO>> drgProfitLossAnalysis(@Valid DrgProfitLossDTO param) {
        return dataStatAnalysisService.drgProfitLossAnalysis(param);
    }

    @GetMapping("/exportDrgProfitLossAnalysisExcel")
    @ApiOperation(value = "导出病组盈亏统计列表excel")
    public void exportDrgProfitLossAnalysisExcel(HttpServletResponse response, DrgProfitLossDTO param) throws Exception {
        dataStatAnalysisService.exportDrgProfitLossAnalysisExcel(response, param);
    }

    @GetMapping("/medicalProtestStat")
    @ApiOperation(value = "医保拒付统计列表")
    public Result<PageEntity<MedicalProtestPageVO>> medicalProtestStat(@Valid MedicalProtestDTO param) {
        return dataStatAnalysisService.medicalProtestStat(param);
    }

    @GetMapping("/exportMedicalProtestStatExcel")
    @ApiOperation(value = "导出医保拒付统计excel")
    public void exportMedicalProtestStatExcel(HttpServletResponse response, MedicalProtestDTO param) throws Exception {
        dataStatAnalysisService.exportMedicalProtestStatExcel(response, param);
    }

    @GetMapping("/medicalTotalStat")
    @ApiOperation(value = "医保总额预付统计列表")
    public Result<PageEntity<MedicalTotalPageVO>> medicalTotalStat(@Valid MedicalTotalDTO param) {
        return dataStatAnalysisService.medicalTotalStat(param);
    }

    @GetMapping("/exportMedicalTotalStatExcel")
    @ApiOperation(value = "导出医保总额预付统计excel")
    public void exportMedicalTotalStatExcel(HttpServletResponse response, MedicalTotalDTO param) throws Exception {
        dataStatAnalysisService.exportMedicalTotalStatExcel(response, param);
    }

    @GetMapping("/SampleDataFind")
    @ApiOperation(value = "样本数据查询列表")
    public Result<List<SampleDataPageVO>> SampleDataFind() {
        return dataStatAnalysisService.SampleDataFind();
    }

    @GetMapping("/exportSampleDataFindExcel")
    @ApiOperation(value = "导出样本数据查询excel")
    public void exportSampleDataFindExcel(HttpServletResponse response) throws Exception {
        dataStatAnalysisService.exportSampleDataFindExcel(response);
    }

    @GetMapping("/doctorGroupProfitLossTotal")
    @ApiOperation(value = "医生组盈亏汇总")
    public Result<List<DoctorGoupSummaryVO>> doctorGroupProfitLossTotal(DoctorGroupSummaryDTO param) {
        List<DoctorGoupSummaryVO> vos = statisticsDoctorFromEsService.getDoctorGoupSummaryVO(param);
        return Result.success().data(vos).build();
    }

    @GetMapping("/doctorGroupProfitLossTotalExportExcel")
    @ApiOperation(value = "医生组盈亏汇总导出excel")
    public void doctorGroupProfitLossTotalExportExcel(HttpServletResponse response, DoctorGroupSummaryDTO param) throws Exception {
        dataStatAnalysisService.doctorGroupProfitLossTotalExportExcel(response, param);
    }

    @GetMapping("/doctorGroupProfitLossAnalysis")
    @ApiOperation(value = "医生组盈亏分析")
    public Result<DoctorGroupProfitLossAnalysisVO> doctorGroupProfitLossAnalysis(DoctorGroupProfitDTO param) {
        return dataStatAnalysisService.doctorGroupProfitLossAnalysis(param);
    }

    @GetMapping("/doctorProfitLossTotal")
    @ApiOperation(value = "医生盈亏汇总")
    public Result<List<DoctorSummaryVO>> doctorProfitLossTotal(DoctorSummaryDTO param) {
        List<DoctorSummaryVO> summaryVOS = statisticsDoctorFromEsService.getDoctorSummaryVO(param);
        return Result.success().data(summaryVOS).build();
    }

    @GetMapping("/doctorProfitLossTotalExportExcel")
    @ApiOperation(value = "医生盈亏汇总导出excel")
    public void doctorProfitLossTotalExportExcel(HttpServletResponse response, DoctorSummaryDTO param) throws Exception {
        dataStatAnalysisService.doctorProfitLossTotalExportExcel(response, param);
    }

    @GetMapping("/doctorProfitLossAnalysis")
    @ApiOperation(value = "医生盈亏分析")
    public Result<DoctorProfitLossAnalysisVO> doctorProfitLossAnalysis(DoctorProfitDTO param) {
        return dataStatAnalysisService.doctorProfitLossAnalysis(param);
    }

    @GetMapping("/dotorProfitTrend")
    @ApiOperation(value = "医生盈亏趋势")
    public Result<ChartLineVO> dotorProfitTrend(@ApiParam("年份") @RequestParam(value = "year") Integer year,
                                                @ApiParam("医生编号数组") @RequestParam(value = "doctorCodeList", required = false) List<String> doctorCodeList){
        return Result.success().data( statisticsDoctorFromEsService.getDoctorCostTrend(year, doctorCodeList)).build();
    }

    @GetMapping("/drgProfitLossAnalysisStat")
    @ApiOperation(value = "病组盈亏分析统计")
    public Result<DrgProfitLossAnalysisVO> drgProfitLossAnalysisStat(DrgProfitDTO param) {
        return dataStatAnalysisService.drgProfitLossAnalysisStat(param);
    }

    @GetMapping("/drgProfitLossProjectTotalStat")
    @ApiOperation(value = "病组盈亏项目统计列表")
    public Result<List<DrgProfitLossProjectTotalPageVO>> drgProfitLossProjectTotalStat(@Valid DrgProfitLossProjectTotalStatDTO param) {
        return dataStatAnalysisService.drgProfitLossProjectTotalStat(param);
    }

    @GetMapping("/drgProfitLossProjectTotalStatExcel")
    @ApiOperation(value = "导出病组盈亏项目统计excel")
    public void drgProfitLossProjectTotalStatExcel(HttpServletResponse response, DrgProfitLossProjectTotalStatDTO param) throws Exception {
        dataStatAnalysisService.drgProfitLossProjectTotalStatExcel(response, param);
    }

    @GetMapping("/caseComplexityAnalysis")
    @ApiOperation(value = "病例复杂程度分析列表")
    public Result<List<CaseComplexityAnalysisPageVO>> caseComplexityAnalysis(@Valid CaseComplexityAnalysisDTO param) {
        return dataStatAnalysisService.caseComplexityAnalysis(param);
    }

    @GetMapping("/caseComplexityAnalysisExcel")
    @ApiOperation(value = "导出病例复杂程度分析excel")
    public void caseComplexityAnalysisExcel(HttpServletResponse response, CaseComplexityAnalysisDTO param) throws Exception {
        dataStatAnalysisService.caseComplexityAnalysisExcel(response, param);
    }

    @GetMapping("/hospitalizationFeeBoxAnalysis")
    @ApiOperation(value = "住院费用箱式分析列表")
    public Result<ChartLineVO> hospitalizationFeeBoxAnalysis(@ApiParam("年份") @RequestParam(value = "year") Integer year) {
        ChartLineVO lineVO = statisticsDoctorFromEsService.getCostBoxData(year);
        return Result.success().data(lineVO).build();
    }


    @GetMapping("/keyProjectsTotalStat")
    @ApiOperation(value = "重点项目统计列表")
    public Result<PageEntity<KeyProjectsTotalStatPageVO>> keyProjectsTotalStat(@Valid KeyProjectsTotalStatExcelDTO param) {
        return dataStatAnalysisService.keyProjectsTotalStat(param);
    }

    @GetMapping("/keyProjectsTotalStatExcel")
    @ApiOperation(value = "导出重点项目统计excel")
    public void keyProjectsTotalStatExcel(HttpServletResponse response, KeyProjectsTotalStatExcelDTO param) throws Exception {
        dataStatAnalysisService.keyProjectsTotalStatExcel(response, param);
    }
}
